﻿using System;
using System.Windows.Forms;
using GuidanceExplorer.Model;

namespace GuidanceExplorer.Controls
{
    [MenuItemAttribute(500, "context\\New Folder", GuidanceExplorer.Commands.NewFolder, Keys.None)]
    [MenuItemAttribute(510, "context\\New Checklist", GuidanceExplorer.Commands.NewChecklist, Keys.None)]
    [MenuItemAttribute(520, "context\\New View", GuidanceExplorer.Commands.NewView, Keys.None)]
    //[MenuItemAttribute(530, "context\\New Search View", GuidanceExplorer.Commands.NewSearchView, typeof(ModelItemMenuItemIsEditableCondition), Keys.None)]
	[MenuItemAttribute(530, "context\\-", null, Keys.None)]
	//[MenuItemAttribute(540, "context\\Save", GuidanceExplorer.Commands.SaveSolutionGuidance, Keys.None)]
    //[MenuItemAttribute(560, "context\\-", null, Keys.None)]
    [MenuItemAttribute(570, "context\\Export Solution Guidance...", GuidanceExplorer.Commands.ExportSolution, Keys.None)]
    [MenuItemAttribute(580, "context\\Import Solution Guidance...", GuidanceExplorer.Commands.ImportSolution, Keys.None)]
    //[MenuItemAttribute(541, "context\\Refresh", GuidanceExplorer.Commands.RefreshSolutionGuidance, Keys.None)]
    //[MenuItemAttribute(550, "context\\Delete Solution Guidance", GuidanceExplorer.Commands.DeleteSolutionGuidance, typeof(ModelItemMenuItemIsEditableCondition), Keys.None)]
	public class SolutionNode : ModelNode<SolutionViews>/*FolderNode */// ModelNode<Folder>
    {
        public static SolutionNode New()
        {
            return new SolutionNode();
        }

        /// <summary>
        /// Default private constructor.
        /// </summary>
        private SolutionNode() : base("<solution node>", 11, 11) 
        {
        }

        /// <summary>
        /// Whether the node is editable.
        /// </summary>
        public override bool CanDrop(IModelItem modelNode)
        {
			ViewNode viewNode = modelNode as ViewNode;
			FolderNode folderNode = modelNode as FolderNode;
			ChecklistNode checkListNode = modelNode as ChecklistNode;

			if (viewNode != null)
			{
				if (viewNode.ModelInstance.RootView)
				{
					return false;
				}

				//Can't drag to its parent.
				if (Object.ReferenceEquals(viewNode.ModelInstance.Container, ModelInstance))
				{
					return false;
				}

				return true;
			}
			else if (folderNode != null)
			{
				//Can't drag to its parent.
				if (Object.ReferenceEquals(folderNode.ModelInstance.Container, ModelInstance))
				{
					return false;
				}

				return true;
			}
			else if (checkListNode != null)
			{
				//Root views cant be dragged
				if (checkListNode.ModelInstance.RootView)
				{
					return false;
				}

				//Can't drag to its parent.
				if (Object.ReferenceEquals(checkListNode.ModelInstance.Container, ModelInstance))
				{
					return false;
				}

				return true;
			}
			else
			{
				return false;
			}
        }

        public override bool IsEditable
        {
            get { return false; }
        }
    }
}
